package edu.chl.dat076.datesite.entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

/**
 *
 * @author Mikey, Christoffer
 */
@Entity
public class SiteUser implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
	@Column(unique = true, nullable = false)
    private String username;
	@Column(nullable = false)
    private String password;
	@Column(nullable = false)
    private String email;
	@Column(length = 2000)
    private String presentation;
    private String profilePic;
	@Column(nullable = false)
    private boolean vip;
	
	@ManyToMany(mappedBy="users")
	@JoinColumn(name="CONVERSATIONS_FK")
	List<Conversation> conversations;
	
	@OneToMany
    private List<SiteUser> friends;
	
	@Embedded
	PartnerCriteria partnerCritera;
	@Embedded
	UserProperties userProperties;

	
	
	public SiteUser() {
	}

	public SiteUser(String username, String password, String email) {
		this.username = username;
		this.password = password;
		this.email = email;
	}
	

	public SiteUser(String username, String password, String email, boolean vip, PartnerCriteria partnerCriteria, UserProperties userProperties) {
		this.username = username;
		this.password = password;
		this.email = email;
		this.vip = vip;
		this.userProperties = userProperties;
	}

	public SiteUser(String username, String password, String email, String presentation, String profilePic, boolean vip, PartnerCriteria partnerCritera, UserProperties userProperties) {
		this.username = username;
		this.password = password;
		this.email = email;
		this.presentation = presentation;
		this.profilePic = profilePic;
		this.vip = vip;
		this.partnerCritera = partnerCritera;
		this.userProperties = userProperties;
	}
	
	
	
    public Long getId() {
        return id;
    }
	
	public String getUsername() {
		return username;
	}
	
	public String getPassword() {
		return password;
	}

	public String getEmail() {
		return email;
	}

	public String getPresentation() {
		return presentation;
	}

	public String getProfilePic() {
		return profilePic;
	}

	public boolean isVip() {
		return vip;
	}

	public List<Conversation> getConversations() {
		return conversations;
	}

	public List<SiteUser> getFriends() {
		return friends;
	}

	public PartnerCriteria getPartnerCritera() {
		return partnerCritera;
	}

	public UserProperties getUserProperties() {
		return userProperties;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	public void setEmail(String email) {
		this.email = email;
	}

	public void setPresentation(String presentation) {
		this.presentation = presentation;
	}

	public void setProfilePic(String profilePic) {
		this.profilePic = profilePic;
	}

	public void setVip(boolean vip) {
		this.vip = vip;
	}

	public void setConversations(List<Conversation> conversations) {
		this.conversations = conversations;
	}
	
	public void addConversation(Conversation conversation) {
		this.conversations.add(conversation);
	}

	public void setFriends(List<SiteUser> friends) {
		this.friends = friends;
	}
	
	public void addFriend(SiteUser siteUser) {
		friends.add(siteUser);
	}
        
        public boolean isFriends(SiteUser siteUser) {
                return friends.contains(siteUser);
        }

	public void setPartnerCritera(PartnerCriteria partnerCritera) {
		this.partnerCritera = partnerCritera;
	}

	public void setUserProperties(UserProperties userProperties) {
		this.userProperties = userProperties;
	}
	
	

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		final SiteUser other = (SiteUser) obj;
		if (this.id != other.id && (this.id == null || !this.id.equals(other.id))) {
			return false;
		}
		if ((this.username == null) ? (other.username != null) : !this.username.equals(other.username)) {
			return false;
		}
		if ((this.password == null) ? (other.password != null) : !this.password.equals(other.password)) {
			return false;
		}
		if ((this.email == null) ? (other.email != null) : !this.email.equals(other.email)) {
			return false;
		}
		if ((this.presentation == null) ? (other.presentation != null) : !this.presentation.equals(other.presentation)) {
			return false;
		}
		if ((this.profilePic == null) ? (other.profilePic != null) : !this.profilePic.equals(other.profilePic)) {
			return false;
		}
		if (this.vip != other.vip) {
			return false;
		}
		if (this.partnerCritera != other.partnerCritera && (this.partnerCritera == null || !this.partnerCritera.equals(other.partnerCritera))) {
			return false;
		}
		if (this.userProperties != other.userProperties && (this.userProperties == null || !this.userProperties.equals(other.userProperties))) {
			return false;
		}
		return true;
	}
	
	
	
	@Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }
        
        
        @Override
        public String toString(){
            return username;
        }
}
